<?php
require_once dirname(__FILE__) . '/../myDebug/myDebug.class.php';

require_once 'connection.class.php';
require_once 'view_render.php';
class L
{
	private static $_ini = array(
		'appini' => array(
			'master_db_host' => 'localhost',
			'master_db_user' => 'root',
			'master_db_password' => '',
			'master_db_name' => 'vertim_league',
			'slave_db_host' => 'localhost',
			'slave_db_user' => 'root',
			'slave_db_password' => '',
			'slave_db_name' => 'vertim_league'
		)
	);
    static function ini($option, $default = null)
    {
        if ($option == '/') return self::$_ini;

        if (strpos($option, '/') === false)
        {
            return array_key_exists($option, self::$_ini)
                ? self::$_ini[$option]
                : $default;
        }

        $parts = explode('/', $option);
        $pos =& self::$_ini;
        foreach ($parts as $part)
        {
            if (!isset($pos[$part])) return $default;
            $pos =& $pos[$part];
        }
        return $pos;
    }
}




function loader($className)
{
	global $app_config;
	@list($mvc, $fileName) = explode('_', $className);
	if($fileName == null){
		$fileName = $mvc;
		$mvc = null;
	}
	
	$paths = array(
		$app_config['APP_DIR'],
		$app_config['APP_DIR'] . '/controller',
	   	$app_config['APP_DIR'] . '/model'
	);
	foreach($paths as $path){
		if(file_exists($path . '/' . $fileName . '.php')){
			include_once $path . '/' . $fileName . '.php';
		}
		if($mvc != null){
			if(file_exists($path . '/' . $fileName . '_' . $mvc . '.php')){
				include_once $path . '/' . $fileName . '_' . $mvc . '.php';
			}
		}	
	}
}
spl_autoload_register('loader');

